package com.xuxk.project.oauth.service.impl;

import com.github.pagehelper.Page;
import com.xuxk.project.oauth.bean.UserRole;
import com.xuxk.project.oauth.dao.UserRoleDao;
import com.xuxk.project.oauth.dto.UserRoleDto;
import com.xuxk.project.oauth.service.UserRoleService;
import com.xuxk.project.oauth.vo.UserRoleVo;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Manager implementation for UserRole, responsible for business processing, and communicate between web and persistence layer.
 * @author 橙云科技有限公司
 */
@Service
public class UserRoleServiceImpl implements UserRoleService {

	@Resource
	private UserRoleDao userRoleDao;
    @Override
	public Page<UserRoleVo>  listUserRoles(Map<String, Object> map, RowBounds rowBounds){


        Page<UserRoleVo> userRolePage =  userRoleDao.listUserRoles(map,rowBounds);
		return userRolePage;
	}
    @Override
	public List<UserRole> listUserRoleByDto(UserRoleDto dto){
        /**
         * 使用例子：
		 *
         * OaEmployeeDto dto1 = new OaEmployeeDto();
         * 		dto1.createCriteria()
         * 			.andIdEqualTo(1L)
         * 			.andFnumberEqualTo("NLW17004");
         * 	userRoleDao.listByDto(dto1);
         */

		return userRoleDao.listByDto(dto);
	}

    @Override
	public void deleteUserRole(Integer id )  {
	    Map<String,Object> map = new HashMap<>();
        map.put("id",id);



		userRoleDao.deleteByPrimaryKey(map);
	}

    /**
    * 全量更新
    * @return
    */
    @Override
    public Integer updateUserRole(UserRole userRole)  {


        return userRoleDao.updateUserRole(userRole);
    }

    /**
    * 部分更新
	* @return
	*/
    @Override
    public Integer patchUpdateUserRole(UserRole userRole)  {


        return userRoleDao.patchUpdateUserRole(userRole);

    }

    /**
    * 新增
	* @return
	*/
    @Override
    public Integer insertUserRole(UserRole userRole)  {


		userRoleDao.insertSelective(userRole);

        return userRole.getId();

    }
    @Override
    public UserRole getUserRole(Integer id ){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);

        return userRoleDao.getUserRole(map);
    }

}